import logging

import colorlog


def console_logger():
    """
    控制台日志颜色
    """
    # 创建logger对象
    logger = logging.getLogger()

    # 定义颜色输出格式
    color_formatter = colorlog.ColoredFormatter(
        '%(log_color)s%(levelname)s[%(asctime)s][%(pathname)s:%(lineno)d]:\n %(message)s',
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red,bg_white',
        }
    )
    # 移除默认的handler
    for handler in logger.handlers:
        if handler.name == 'console':
            handler.setFormatter(color_formatter)

